<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>${empty medicine ? '添加药材' : '修改药材'} - 学生信息管理系统</title>
    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }

        body {
            font-family: "Microsoft YaHei", Arial, sans-serif;
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            min-height: 100vh;
            padding: 20px;
        }

        .container {
            max-width: 900px;
            margin: 0 auto;
            background: white;
            border-radius: 10px;
            box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
            padding: 30px;
        }

        .header {
            text-align: center;
            margin-bottom: 30px;
            padding-bottom: 20px;
            border-bottom: 2px solid #667eea;
        }

        .header h1 {
            color: #333;
            font-size: 28px;
        }

        .form-group {
            margin-bottom: 20px;
        }

        .form-group label {
            display: block;
            margin-bottom: 8px;
            color: #555;
            font-weight: bold;
        }

        .form-group label .required {
            color: #e74c3c;
            margin-left: 3px;
        }

        .form-group input[type="text"],
        .form-group textarea {
            width: 100%;
            padding: 10px 15px;
            border: 2px solid #ddd;
            border-radius: 5px;
            font-size: 14px;
            font-family: "Microsoft YaHei", Arial, sans-serif;
        }

        .form-group input[type="text"]:focus,
        .form-group textarea:focus {
            outline: none;
            border-color: #667eea;
        }

        .form-group textarea {
            min-height: 100px;
            resize: vertical;
        }

        .form-group .hint {
            font-size: 12px;
            color: #999;
            margin-top: 5px;
        }

        .error-message {
            background: #ffe6e6;
            color: #c0392b;
            padding: 10px 15px;
            border-radius: 5px;
            margin-bottom: 20px;
            border-left: 4px solid #e74c3c;
        }

        .form-actions {
            text-align: center;
            margin-top: 30px;
            padding-top: 20px;
            border-top: 1px solid #e0e0e0;
        }

        .btn {
            display: inline-block;
            padding: 12px 30px;
            background: #667eea;
            color: white;
            text-decoration: none;
            border-radius: 5px;
            transition: background 0.3s;
            margin: 0 10px;
            border: none;
            cursor: pointer;
            font-size: 16px;
        }

        .btn:hover {
            background: #5568d3;
        }

        .btn-success {
            background: #27ae60;
        }

        .btn-success:hover {
            background: #229954;
        }

        .btn-secondary {
            background: #95a5a6;
        }

        .btn-secondary:hover {
            background: #7f8c8d;
        }

        .section-title {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            color: white;
            padding: 10px 15px;
            border-radius: 5px;
            margin: 25px 0 15px 0;
            font-size: 16px;
        }
    </style>
    <script>
        function validateForm() {
            var medicineNo = document.getElementById("medicineNo").value.trim();
            var medicineName = document.getElementById("medicineName").value.trim();
            
            if (medicineNo === "") {
                alert("请输入药材编号！");
                return false;
            }
            
            if (medicineName === "") {
                alert("请输入中药名！");
                return false;
            }
            
            return true;
        }
    </script>
</head>
<body>
    <div class="container">
        <div class="header">
            <h1>${empty medicine ? '➕ 添加药材' : '✏️ 修改药材'}</h1>
        </div>

        <c:if test="${not empty error}">
            <div class="error-message">
                ❌ ${error}
            </div>
        </c:if>

        <form action="${pageContext.request.contextPath}/medicine" method="post" onsubmit="return validateForm()">
            <input type="hidden" name="action" value="${empty medicine ? 'save' : 'update'}">
            <c:if test="${not empty medicine}">
                <input type="hidden" name="id" value="${medicine.id}">
            </c:if>

            <div class="section-title">📋 基本信息</div>

            <div class="form-group">
                <label for="medicineNo">药材编号<span class="required">*</span></label>
                <input type="text" id="medicineNo" name="medicineNo" 
                       value="${medicine.medicineNo}" 
                       placeholder="例如：YC001" required>
                <div class="hint">请输入唯一的药材编号</div>
            </div>

            <div class="form-group">
                <label for="medicineName">中药名<span class="required">*</span></label>
                <input type="text" id="medicineName" name="medicineName" 
                       value="${medicine.medicineName}" 
                       placeholder="例如：人参" required>
            </div>

            <div class="form-group">
                <label for="alias">别名</label>
                <input type="text" id="alias" name="alias" 
                       value="${medicine.alias}" 
                       placeholder="例如：棒槌、神草、土精">
                <div class="hint">多个别名用顿号（、）分隔</div>
            </div>

            <div class="section-title">🌱 来源与分布</div>

            <div class="form-group">
                <label for="source">来源</label>
                <textarea id="source" name="source" 
                          placeholder="例如：五加科植物人参的干燥根和根茎">${medicine.source}</textarea>
            </div>

            <div class="form-group">
                <label for="environment">生长环境分布</label>
                <textarea id="environment" name="environment" 
                          placeholder="例如：生长于北纬33度-48度之间的海拔数百米的山地缓坡...">${medicine.environment}</textarea>
            </div>

            <div class="section-title">💊 药性与功效</div>

            <div class="form-group">
                <label for="natureFlavor">性味</label>
                <input type="text" id="natureFlavor" name="natureFlavor" 
                       value="${medicine.natureFlavor}" 
                       placeholder="例如：甘、微苦，微温。归脾、肺、心、肾经">
            </div>

            <div class="form-group">
                <label for="mainFunction">主治功能</label>
                <textarea id="mainFunction" name="mainFunction" 
                          placeholder="例如：大补元气，复脉固脱，补脾益肺...">${medicine.mainFunction}</textarea>
            </div>

            <div class="form-group">
                <label for="usageDosage">用法用量</label>
                <textarea id="usageDosage" name="usageDosage" 
                          placeholder="例如：3-9g，另煎兑服。不宜与藜芦、五灵脂同用">${medicine.usageDosage}</textarea>
            </div>

            <div class="form-actions">
                <button type="submit" class="btn btn-success">
                    ${empty medicine ? '💾 保存' : '✅ 更新'}
                </button>
                <a href="${pageContext.request.contextPath}/medicine?action=list" 
                   class="btn btn-secondary">❌ 取消</a>
            </div>
        </form>
    </div>
</body>
</html>

